package com.cn.netty.main.config;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.concurrent.DefaultEventExecutor;
import io.netty.util.concurrent.EventExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


/**
 * Created by chenyuncong on 2018/7/3.
 */

@Component("springProtocolInitializer")
//@Qualifier("springProtocolInitializer")
public class StringProtocolInitalizer extends ChannelInitializer<SocketChannel> {

    @Autowired
    StringDecoder stringDecoder;

    @Autowired
    StringEncoder stringEncoder;

    @Autowired
    ServerHandler serverHandler;

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
//        EventExecutor e1 = new DefaultEventExecutor();
        pipeline.addLast("decoder", stringDecoder);
        pipeline.addLast("handler", serverHandler);
        pipeline.addLast("encoder", stringEncoder);
//        pipeline.addLast(e1,null);
    }

//    public StringDecoder getStringDecoder() {
//        return stringDecoder;
//    }
//
//    public void setStringDecoder(StringDecoder stringDecoder) {
//        this.stringDecoder = stringDecoder;
//    }
//
//    public StringEncoder getStringEncoder() {
//        return stringEncoder;
//    }
//
//    public void setStringEncoder(StringEncoder stringEncoder) {
//        this.stringEncoder = stringEncoder;
//    }
//
//    public ServerHandler getServerHandler() {
//        return serverHandler;
//    }
//
//    public void setServerHandler(ServerHandler serverHandler) {
//        this.serverHandler = serverHandler;
//    }

}
